package com.product.system.service.impl;

import com.product.system.domain.ArgpFactory;
import com.product.system.domain.FactoryAndPosts;
import com.product.system.mapper.ArgpFactoryMapper;
import com.product.system.mapper.FactoryAndPostsMapper;
import com.product.system.service.ArgpFactoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class ArgpFactoryServicelmpl implements ArgpFactoryService {

    @Autowired
    ArgpFactoryMapper argpFactoryMapper;


    @Autowired
    FactoryAndPostsMapper factoryAndPostsMapper;

    @Override
    public List<ArgpFactory> listArgpFactory(ArgpFactory argpFactory) {
        return argpFactoryMapper.listArgpFactory(argpFactory);
    }

    @Override
    public void addArgpFactory(ArgpFactory argpFactory) {
        argpFactoryMapper.addArgpFactory(argpFactory);
    }

    @Override
    public void updateId(String id) {
        argpFactoryMapper.updateId(id);
    }

    @Override
    public void addSave(ArgpFactory argpFactory) {
        argpFactoryMapper.addSave(argpFactory);
        System.out.println(argpFactory.getPostsAll());
        if(argpFactory.getPostsAll()!=null){
            List<FactoryAndPosts> andPosts=new ArrayList<>();
            for (Integer integer : argpFactory.getPostsAll()) {
                FactoryAndPosts factoryAndPosts = new FactoryAndPosts();
                factoryAndPosts.setFactoryId(argpFactory.getId());
                factoryAndPosts.setPostsId(integer);
                andPosts.add(factoryAndPosts);
            }
            factoryAndPostsMapper.insertAndPosts(andPosts);
        }
    }

    @Override
    public void updateFactory(ArgpFactory argpFactory) {
        argpFactoryMapper.updateFactory(argpFactory);
    }

    @Override
    public List<ArgpFactory> listGetArgpFactory() {
        return argpFactoryMapper.listGetArgpFactory();
    }


}
